package org.apache.servicecomb.samples.practise.houserush.user.center.aggregate;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;

import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;


import javax.persistence.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


/**
 * @Author: Snake Man
 * @system: 建筑楼实体类
 * @DateTime: 2021/12/30 22:54
 * @Description:
 */

@Data
@Entity
@Table(name = "buildings")
@EntityListeners(AuditingEntityListener.class)
@Where(clause = "deleted_at is null")
@SQLDelete(sql = "update buildings set deleted_at = now() where id = ?")
public class Building {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int id;


    @ManyToOne   //配置多对一
    @JoinColumn(name = "realestate_id")
    private Realestate realestate;

    private String name;

    private Integer sequenceInRealestate;

    @Temporal(TemporalType.TIMESTAMP)
    private Date deletedAt;

    @CreatedDate
    @Temporal(TemporalType.TIMESTAMP)
    private Date createdAt;

    @LastModifiedDate
    @Temporal(TemporalType.TIMESTAMP)
    private Date updatedAt;

    @JsonIgnoreProperties(ignoreUnknown = true, value = {"building"})
    @OneToMany(mappedBy = "building")
    @Where(clause = "deleted_at is null")
    private List<House> houses = new ArrayList<>();
}
